//-----------------------------------------------------------------------------
//  File          : midware.h
//  Module        : T800
//  Description   : Header for Middleware.
//  Author        : Lewis
//  Notes         :
//
// ============================================================================
// | Naming conventions                                                       |
// | ~~~~~~~~~~~~~~~~~~                                                       |
// |         Struct/Array : Leading s                                         |
// |             Constant : Leading K                                         |
// |      Global Variable : Leading g  (variable use outside one C file)      |
// |                                                                          |
// |   BYTE( 8 Bits) size : Leading b                                         |
// |   CHAR( 8 Bits) size : Leading c                                         |
// |   WORD(16 Bits) size : Leading w                                         |
// |  DWORD(32 Bits) size : Leading d                                         |
// |    int(32 Bits) size : Leading i                                         |
// | DDWORD(64 Bits) size : Leading dd                                        |
// |              Pointer : Leading p                                         |
// |                                                                          |
// |    Function argument : Leading a                                         |
// |       Local Variable : All lower case                                    |
// |                                                                          |
// | Examples:                                                                |
// |                Array : Leading s, (sb = arrary of byte, etc)             |
// |              Pointer : Leading p, (pb = pointer of byte, etc)            |
// ============================================================================
//
//  Date          Who         Action
//  ------------  ----------- -------------------------------------------------
//  01 Apr  2009  Lewis       Initial Version.
//-----------------------------------------------------------------------------
#ifndef _INC_MIDWARE_H_
#define _INC_MIDWARE_H_

#include <string.h>
#include "stdio_s.h"
#include "common.h"
#include "system.h"
#include "basecall.h"


//-----------------------------------------------------------------------------
//   Common Defines
//-----------------------------------------------------------------------------
#define MIDWARE_ID          0x0F

// Support LCD Type
//
// #define SUPPORT_128X64       TRUE
//
#ifndef SUPPORT_128X64
#define SUPPORT_320X240
#endif

//***********************************
// => Keyboard
//***********************************
// Key code define
#define MWKEY_ENTER           0x10
#define MWKEY_CANCL           0x11
#define MWKEY_CLR             0x12
#define MWKEY_FUNC            0x13
#define MWKEY_TRANS           0x14
#define MWKEY_SETTLE          0x15
#define MWKEY_FEED            0x16
#define MWKEY_OTHERS          0x17
#define MWKEY_OCARD           0x18
#define MWKEY_BKSP            0x19
#define MWKEY_EPS             0x1A
#define MWKEY_ALPHA           0x1B
#define MWKEY_MENU            0x1C
#define MWKEY_REPRN           0x1D
#define MWKEY_0               0x30
#define MWKEY_1               0x31
#define MWKEY_2               0x32
#define MWKEY_3               0x33
#define MWKEY_4               0x34
#define MWKEY_5               0x35
#define MWKEY_6               0x36
#define MWKEY_7               0x37
#define MWKEY_8               0x38
#define MWKEY_9               0x39
#define MWKEY_00              0x3A
#define MWKEY_UP              0x41
#define MWKEY_DN              0x42
#define MWKEY_LEFT            0x43
#define MWKEY_RIGHT           0x44
#define MWKEY_FUNC1           0x45
#define MWKEY_FUNC2           0x46
#define MWKEY_FUNC3           0x47
#define MWKEY_FUNC4           0x48
#define MWKEY_FUNC5           0x49
#define MWKEY_FUNC6           0x4A
#define MWKEY_FUNC7           0x4B
#define MWKEY_FUNC8           0x4C
#define MWKEY_SELECT          0x4D
#define MWKEY_DOT             0x4E
#define MWKEY_LEFT1           0x4F
#define MWKEY_LEFT2           0x50
#define MWKEY_LEFT3           0x51
#define MWKEY_LEFT4           0x52
#define MWKEY_RIGHT1          0x53
#define MWKEY_RIGHT2          0x54
#define MWKEY_RIGHT3          0x55
#define MWKEY_RIGHT4          0x56
#define MWKEY_FBACK           0x57
#define MWKEY_POWER           0x58

// BYTE os_kbd_getkey();
#define KbdFlushMW()                sys_func0(OS_FN_KBD_GETKEY)


//***********************************
// => Real time clock
//***********************************
// 14 bytes RTC format = CCYYMMDDHHMMSS
// BOOLEAN os_rtc_get(BYTE * a_dtg);
#define RtcGetMW(x)                 sys_func1(OS_FN_RTC_GET,(DWORD)(x))
// BOOLEAN os_rtc_set(BYTE * a_dtg);
#define RtcSetMW(x)                 sys_func1(OS_FN_RTC_SET,(DWORD)(x))


//***********************************
// => Timer
//***********************************
// DWORD os_timer_open();
#define TimerOpenMW()           		sys_func0(OS_FN_TIMER_OPEN)
// void os_timer_close(DWORD a_idx);
#define TimerCloseMW(x)         		sys_func1(OS_FN_TIMER_CLOSE,(DWORD)(x))
// void os_timer_set(DWORD a_idx,DWORD a_value);
#define TimerSetMW(x,y)             sys_func2(OS_FN_TIMER_SET,(DWORD)(x),(DWORD)(y))
// DWORD os_timer_get(DWORD a_idx);
#define TimerGetMW(x)               sys_func1(OS_FN_TIMER_GET,(DWORD)(x))


//***********************************
// => Buzzer
//***********************************
// BOOLEAN os_beep_open();
#define BeepOpenMW()            		sys_func1(OS_FN_BUZ_OPEN,(DWORD)(0))
#define BeepOpen1MW(x)            		sys_func1(OS_FN_BUZ_OPEN,(DWORD)(x))
// void os_beep_close();
#define BeepCloseMW()           		sys_func0(OS_FN_BUZ_CLOSE)
// void os_beep_sound(WORD a_ontime,WORD a_offtime,WORD a_count);
#define BeepMW(x,y,z)               sys_func3(OS_FN_BUZ_BEEP,(DWORD)(x),(DWORD)(y),(DWORD)(z))
// void os_beep_state(DWORD a_state);
#define BeepOnOffMW(x)              sys_func1(OS_FN_BUZ_STATE,(DWORD)(x))


//***********************************
// => Encryption
//***********************************
// RSA key struct define
struct MW_RSA_KEY {
  DWORD  d_exponent;
  DWORD  d_keysize;
  DWORD  sd_key[64];
  DWORD  d_key_idx;
};		//T_KEY

// SSL
struct MW_MD5_CONTEXT {
  DWORD sd_total[2];
  DWORD sd_state[4];
  BYTE  sb_buffer[64];
};		//T_MD5_CONTEXT

struct MW_MD4_CONTEXT {
  DWORD sd_total[2];
  DWORD sd_state[4];
  BYTE  sb_buffer[64];
};		//T_MD4_CONTEXT

struct MW_SHA1_CONTEXT {
  DWORD sd_total[2];
  DWORD sd_state[5];
  BYTE  sb_buffer[64];
};	//T_SHA1_CONTEXT

struct MW_RC4_STATE {
  DWORD d_x;
  DWORD d_y;
  DWORD sd_m[256];
};	//T_RC4_STATE

// BOOLEAN os_rsa(void * a_msg,T_KEY * a_key);
#define RsaMW(x,y)                  sys_func2(OS_FN_RSA,(DWORD)(x),(DWORD)(y))
// void os_sha1(void * a_omsg,void * a_imsg,DWORD a_len);
#define Sha1MW(x,y,z)               sys_func3(OS_FN_SHA1,(DWORD)(x),(DWORD)(y),(DWORD)(z))
// void os_md5_init(T_MD5_CONTEXT * a_c);
#define MD5InitMW(x)            		sys_func1(OS_FN_MD5_INIT,(DWORD)x)
// void os_md5_process(T_MD5_CONTEXT * a_c, BYTE* a_input, DWORD a_length);
#define MD5ProcessMW(x,y,z)    			sys_func3(OS_FN_MD5_PROCESS,(DWORD)x,(DWORD)y,z)
// void os_md5_finish(T_MD5_CONTEXT * a_c, BYTE* a_digest);
#define MD5FinishMW(x,y)        		sys_func2(OS_FN_MD5_FINISH,(DWORD)x,(DWORD)y)
// void os_sha1_init(T_SHA1_CONTEXT * a_c);
#define Sha1InitMW(x)           		sys_func1(OS_FN_SHA1_INIT,(DWORD)x)
// void os_sha1_process(T_SHA1_CONTEXT * a_c, BYTE* a_input, DWORD a_length);
#define Sha1ProcessMW(x,y,z)    		sys_func3(OS_FN_SHA1_PROCESS,(DWORD)x,(DWORD)y,z)
// void os_sha1_finish(T_SHA1_CONTEXT * a_c, BYTE * a_digest);
#define Sha1FinishMW(x,y)       		sys_func2(OS_FN_SHA1_FINISH,(DWORD)x,(DWORD)y)
// void os_rc4_setup(T_RC4_STATE * a_c, T_KEY * a_input, DWORD a_length);
#define RC4SetupMW(x,y,z)       		sys_func3(OS_FN_RC4_SETUP,(DWORD)x,(DWORD)y,z)
// void os_rc4_encrypt(T_RC4_STATE_T * a_c, BYTE * a_input, DWORD a_length);
#define RC4EncryptMW(x,y,z)      		sys_func3(OS_FN_RC4_ENCRYPT,(DWORD)x,(DWORD)y,(DWORD)(z))
// void os_md5_init(T_MD5_CONTEXT * a_c);
#define MD4InitMW(x)            		sys_func1(OS_FN_MD5_INIT,(DWORD)x)
// void os_md4_process(T_MD4_CONTEXT * a_c, BYTE * a_input, DWORD a_length);
#define MD4ProcessMW(x,y,z)     		sys_func3(OS_FN_MD4_PROCESS,(DWORD)x,(DWORD)y,z)
// void os_md4_finish(T_MD4_CONTEXT * a_c, BYTE * a_digest);
#define MD4FinishMW(x,y)        		sys_func2(OS_FN_MD4_FINISH,(DWORD)x,(DWORD)y)


//***********************************
// => Thread
//***********************************
// BOOLEAN os_thread_open(); // system use only
//#define ThreadOpenMW()        sys_func0(OS_FN_THREAD_OPEN)
// BOOLEAN os_thread_close(); // system use only
//#define ThreadCloseMW()       sys_func0(OS_FN_THREAD_CLOSE)
// BOOLEAN os_thread_create(DWORD a_address,DWORD a_resolution);
#define ThreadCreateMW(x,y)   sys_func2(OS_FN_THREAD_CREATE,(DWORD)(x),(DWORD)(y))
// BOOLEAN os_thread_delete(DWORD a_address);
#define ThreadDeleteMW(x)     sys_func1(OS_FN_THREAD_DELETE,(DWORD)(x))
//void os_thread_lock();
#define ThreadLockMW()        sys_func0(OS_FN_THREAD_LOCK)
//void os_thread_unlock()
#define ThreadUnlockMW()      sys_func0(OS_FN_THREAD_UNLOCK)
//void os_thread_push()
//#define ThreadPushMW()        sys_func0(OS_FN_THREAD_PUSH)
//void os_thread_pop()
//#define ThreadPopMW()         sys_func0(OS_FN_THREAD_POP)
//void os_thread_return()
#define ThreadReturnMW()      sys_func0(OS_FN_THREAD_RETURN)


//***********************************
// => Application
//***********************************
struct MW_APPL_INFO {  //T_APP_INFO
  WORD w_checksum;
  WORD w_disp_checksum;
  BYTE sb_agent_id[8];
  BYTE sb_app_name[13];
  BYTE b_version;
  BYTE b_sub_version;
  BYTE b_type;
  BYTE b_appid;
};
// BOOLEAN os_app_info(DWORD a_appid,T_APP_INFO * a_pdptr);
#define AppInfoGetMW(x,y)     sys_func2(OS_FN_APP_INFO,(DWORD)(x),(DWORD)(y))
// BOOLEAN os_app_search_id(DWORD a_appid);
#define IsAppIdExistMW(x)     sys_func1(OS_FN_APP_SEARCH_ID,(DWORD)(x))
// BOOLEAN os_app_search_name(BYTE * a_name,DWORD a_control);
#define IsAppExistMW(x,y)     sys_func2(OS_FN_APP_SEARCH_NAME,(DWORD)(x),(DWORD)(y))
// BOOLEAN os_app_get_virgin(DWORD a_appid);
#define IsAppVirginMW(x)      sys_func1(OS_FN_APP_GET_VIRGIN,(DWORD)(x))
// void os_app_clear_virgin(DWORD a_appid);
#define AppVirginOffMW(x)     sys_func1(OS_FN_APP_CLR_VIRGIN,(DWORD)(x))
//void SwitchAppMW(DWORD aAppId, DWORD aParam1, DWORD aParam2, DWORD aParam3)
//#define SwitchAppMW(id,x,y,z)     os_switch_app(id, x, y, z)
#define SwitchAppMW(id,x,y,z)     os_call_app(id, x, y, z)


//***********************************
// => Dynamic memory
//***********************************
// void * os_malloc(DWORD a_size);
#define MallocMW(x)           (void *)sys_func1(OS_FN_MALLOC,(DWORD)(x))
// void * os_realloc(void * a_bptr,DWORD a_size);
//#define ReallocMW(x,y)        sys_func2(OS_FN_REALLOC,(DWORD)(x),(DWORD)(y))
// void os_free(void * a_bptr);
#define FreeMW(x)             sys_func1(OS_FN_FREE,(DWORD)(x))


//***********************************
// => system utility
//***********************************
//void SprintfMW(const char *aFormatStr[,aArgument....])
#define SprintfMW            	sprintf
// BOOLEAN os_rand(void * a_dest);
#define RandMW(x)             sys_func1(OS_FN_RAND,(DWORD)(x))
// void os_sleep(void);
#define SleepMW()             sys_func0(OS_FN_SLEEP)
// void os_reset(void);
#define ResetMW()             sys_func0(OS_FN_RESET)
#define PowerOffMW()          sys_func0(OS_FN_OFF)
// DWORD os_free_run(void);
#define FreeRunMW()           sys_func0(OS_FN_FREE_RUN)

// define system config index
#define   MW_SYSCFG_SERIAL_NO      	K_CF_SerialNo      // read only
#define   MW_SYSCFG_TID            	K_CF_Tid           // read only
#define   MW_SYSCFG_LCDCONTRAST     K_CF_Max           // T800 Not Support 
#define   MW_SYSCFG_ETHER_ID        K_CF_EtherID       // read only
#define   MW_SYSCFG_PPPIP           K_CF_PppFixIP      // r/w
#define   MW_SYSCFG_IP             	K_CF_IP            // r/w
#define   MW_SYSCFG_NETMASK        	K_CF_Netmask       // r/w
#define   MW_SYSCFG_GATEWAY        	K_CF_Gateway       // r/w
#define   MW_SYSCFG_DNS1            K_CF_DNS1          // r/w
#define   MW_SYSCFG_DNS2            K_CF_DNS2          // r/w
#define   MW_SYSCFG_UDP_PORT        K_CF_UDPPort       // r/w
#define   MW_SYSCFG_TCP_PORT        K_CF_TCPPort       // r/w
#define   MW_SYSCFG_DHCP_ENABLE    	K_CF_DHCPEnable    // r/w
#define   MW_SYSCFG_MDM_COUNTRY     K_CF_MdmCountry    // r/w
#define   MW_SYSCFG_MDM_TX_PWR      K_CF_MdmTxPwr      // r/w
#define   MW_SYSCFG_MDM_DT_PWR      K_CF_MdmDTPwr      // r/w
#define   MW_SYSCFG_MDM_DTMF_PWR    K_CF_MdmDTMFPwr    // r/w
#define   MW_SYSCFG_LOGO           	K_CF_Logo          // write only
#define   MW_SYSCFG_TAMPERED        K_CF_Tampered      // r/w
#define   MW_SYSCFG_RDLLINF         K_CF_RdllInf       // r/w
#define   MW_SYS_MDMU80             K_CF_MdmU80        // r/w
#define   MW_SYSCFG_HWCFG           K_CF_HwConfig      // read only (Product code)
#define   MW_SYSCFG_LCDB            K_CF_LcdBrightness // read only
#define   MW_SYSCFG_LCDTIMEOUT      K_CF_LcdTimeout    // read only
#define   MW_SYSCFG_SIMSEL          K_CF_SimSelect     // read only
#define   MW_SYSCFG_KBDBL           K_CF_KbdBL         // r/w
#define   MW_SYSCFG_MAX             K_CF_Max

// DWORD config_length(DWORD a_idx);
#define SysCfgLenMW(x)    		sys_func1(OS_FN_CONFIG_LENGTH,(DWORD)(x))
// BOOLEAN config_read(DWORD a_idx,BYTE * a_dest);
#define GetSysCfgMW(x,y)    	sys_func2(OS_FN_CONFIG_READ,(DWORD)(x),(DWORD)(y))
// BOOLEAN config_write(DWORD a_idx,BYTE * a_src);
#define PutSysCfgMW(x,y)   		sys_func2(OS_FN_CONFIG_WRITE,(DWORD)(x),(DWORD)(y))
// BOOLEAN config_update(void);
#define UpdSysCfgMW()     		sys_func0(OS_FN_CONFIG_UPDATE)


struct MW_NIF_INFO {
  DWORD d_ip;
  DWORD d_netmask;
  DWORD d_gateway;
  DWORD s_dns[2];
};

#define MW_NIF_ETHERNET        0
#define MW_NIF_PPP             1

// DWORD NetInfo(DWORD aNif, MW_NIF_INFO *aNif)
#define NetInfoMW(x,y)         base_func2(BS_FN_NET_NIF_INFO,(DWORD)(x),(DWORD)(y))



//***********************************
// => file system
//***********************************
// seek location for fSeekMW()
#define MW_FSEEK_SET         0
#define MW_FSEEK_CUR         (DWORD)-2
#define MW_FSEEK_END         (DWORD)-1

// create file
#define MW_FCREATE_SHARE            1       // bit 0
#define MW_FCREATE_ENCRYPT          2       // bit 1

struct MW_FILE_HDR {
  DWORD d_attr;
  DWORD d_filelen;
  BYTE  sb_name[20];
  BYTE  sb_create_date[7];
  BYTE  sb_last_update[7];
};


//-----------------------------------------------------------------------------
//   Standard IO Device Defines
//-----------------------------------------------------------------------------
// Device file name
#define DEV_MSR1 "/dev/msr1"
#define DEV_ICC1 "/dev/icc1"
#define DEV_SD1  "/dev/sd1"
#define DEV_LPT1 "/dev/lpt1"
#define DEV_LPT2 "/dev/lpt2"
#define DEV_AUX0 "/dev/aux0"
#define DEV_AUX1 "/dev/aux1"
#define DEV_AUX2 "/dev/aux2"
#define DEV_TCP1 "/dev/tcp1"
#define DEV_UDP1 "/dev/udp1"
#define DEV_ICMP "/dev/icmp"
#define DEV_PPP1 "/dev/ppp1"
#define DEV_FTP1 "/dev/ftp1"
#define DEV_MDM1 "/dev/mdm1"
#define DEV_CDC1 "/dev/cdc1"
#define DEV_USBS "/dev/usbs"
#define DEV_DNS1 "/dev/dns1"
#define DEV_HTTP "/dev/http"
#define DEV_GPRS "/dev/gprs"

// standard IO For OpenMW
#define MW_CLOSE            0x0000
#define MW_OPEN             0x0001
#define MW_RDONLY           0x0002
#define MW_WRONLY           0x0004
#define MW_RDWR             0x0006
#define MW_SEEK             0x0008
#define MW_CREAT            0x0100
#define MW_TRUNC            0x0200
#define MW_APPEND           0x0300

// standard IO For LSeekMW
#define MW_SEEK_SET         0
#define MW_SEEK_CUR         1
#define MW_SEEK_END         2

// standard IO Operation Error Code
#define MWESUCCESS        0
#define MWEINVFD         -1
#define MWEINVLEN        -2
#define MWEINVOPR        -3
#define MWEOPENED        -4
#define MWECLOSED        -5
#define MWEUNDEFINE      -6

// => MSR define
//***********************************
// MSR IOCtl
#define IO_MSR_CFG          0x0001
#define IO_MSR_STATUS       0x0002
#define IO_MSR_RXLEN        0x0003
#define IO_MSR_RESET        0x0004

// Msr Config MODE
#define MW_TRACK2        0x01
#define MW_TRACK1        0x02
#define MW_TRACK3        0x04

// MSR status
#define MW_TRACK2_ERR    0x0100
#define MW_TRACK1_ERR    0x0200
#define MW_TRACK3_ERR    0x0400

// MSR special chars
#define START2_SENTINEL 0x3B
#define START3_SENTINEL 0x3B
#define START1_SENTINEL 0x25
#define END_SENTINEL    0x3F
#define SEPERATOR2      0x3D

// MSR configuration
struct MW_MSR_CFG {
  BYTE b_mode;
  BYTE b_speed;
};

// Track 1 data
struct MW_TRK1BUF {
  BYTE b_len;
  BYTE sb_content[K_Trk1BufLen];
};

// Track 2 data
struct MW_TRK2BUF {
  BYTE b_len;
  BYTE sb_content[K_Trk2BufLen];
};

// Track 3 data
struct MW_TRK3BUF {
  BYTE b_len;
  BYTE sb_content[K_Trk3BufLen];
};

// => ICC define
//***********************************
// ICC IOCtl
#define IO_ICC_SELECT       0x0001
#define IO_ICC_INSERTED     0x0002
#define IO_ICC_ON           0x0003
#define IO_ICC_OFF          0x0004
#define IO_ICC_CHANGE       0x0005
#define IO_ICC_T1           0x0006
#define IO_ICC_MEMON        0x0007
#define IO_ICC_MEMOFF       0x0008
#define IO_ICC_MEMHIST      0x0009
#define IO_ICC_MEMT0        0x000A

// ICC type T1
struct MW_ICC_T1 {	// T_T1
  BYTE *pb_sad_buf;
  WORD  w_sad_len;
  BYTE  b_sad;
  BYTE  b_rfu1;
  BYTE *pb_dad_buf;
  WORD  w_dad_len;
  BYTE  b_dad;
  BYTE  b_rfu2;
};

// ICC type T0
struct MW_ICC_T0 {	// T_T0
  BYTE  b_output;
  BYTE  b_class;
  BYTE  b_command;
  BYTE  b_p1;
  BYTE  b_p2;
  BYTE  b_p3;
  WORD  w_response;
  BYTE *pb_mblk;
};

// => MMC/SD define
//***********************************
// MMC/SD IOCtl
#define IO_SD_BLKSIZE       0x0001
#define IO_SD_PSTATUS       0x0002
#define IO_SD_GETCID        0x0003
#define IO_SD_GETCSD        0x0004
#define IO_SD_CARDSIZE      0x0005

// => LPT define
//***********************************
// For IOCtlMW
// LPT
#define IO_LPT_RESET        0x0001
#define IO_LPT_COMMAND      0x0002

// LPT STATE
#define LPT_STS_GET         0
#define LPT_STS_ERESTART    1
#define LPT_STS_ERESET      2
#define LPT_STS_RESET       3

// LPT command
#define MW_LPT_BOLD_OFF         "\x1B\x42\x30"
#define MW_LPT_BOLD_ON          "\x1B\x42\x31"
#define MW_LPT_UNDERLINE_OFF    "\x1B\x55\x30"
#define MW_LPT_UNDERLINE_ON     "\x1B\x55\x31"
#define MW_LPT_INVERTED_OFF     "\x1B\x49\x30"
#define MW_LPT_INVERTED_ON      "\x1B\x49\x31"
#define MW_LPT_2WIDTH_OFF       "\x1B\x57\x30"
#define MW_LPT_2WIDTH_ON        "\x1B\x57\x31"
#define MW_LPT_2HEIGHT_OFF      "\x1B\x48\x30"
#define MW_LPT_2HEIGHT_ON       "\x1B\x48\x31"
#define MW_LPT_FONT_NORMAL      "\x1B\x46\x30"    // 16(H)x12(W)
#define MW_LPT_FONT_SMALL       "\x1B\x46\x31"    // 16(H)x8(W)
#define MW_LPT_FONT_ENLARGED    "\x1B\x46\x32"    // 16(H)x12(W)
#define MW_LPT_FONT_DEFAULT     "\x1B\x46\x33"    // 16(H)x8(W)
#define MW_LPT_FONT_SP_NORMAL   "\x1B\x46\x34"    // size returned by SPFONT
#define MW_LPT_FONT_SP_T        "\x1B\x46\x35"    // size returned by SPFONT
#define MW_LPT_FONT_SP_SP       "\x1B\x46\x36"    // size returned by SPFONT
#define MW_LPT_FEED_N           "\x1B\x4A"        // feed paper n lines (insert number N after command string)
#define MW_LPT_GRAPHIC          "\x1B\x4B"        // print graphic (insert [height][width][image])
#define MW_LPT_RESET            "\x1B\x40"        // reset
#define MW_LPT_HALFDOT_OFF      "\x1B\x44\x30"
#define MW_LPT_HALFDOT_ON       "\x1B\x44\x31"

// LPT status
#define MW_LPT_STAT_START_FINISH        0
#define MW_LPT_STAT_HIGH_TEMP           1
#define MW_LPT_STAT_LOW_VOL             2
#define MW_LPT_STAT_PAPER_OUT           3
#define MW_LPT_STAT_NOT_START           4
#define MW_LPT_STAT_IN_PROGRESS         5
#define MW_LPT_STAT_LOW_VOL_RESUME      6
#define MW_LPT_STAT_UNDEFINE_ERR        7

#define MW_LPT_TEMP_HIGH                0x0100
#define MW_LPT_PAPER_OUT                0x0200
#define MW_LPT_LOW_VOLT                 0x0400
#define MW_LPT_PRINTING                 0x0800
#define MW_LPT_FINISH                   0x1000

// => AUX define
//***********************************
// For IOCtlMW
#define IO_AUX_CFG          0x0001
#define IO_AUX_TX_RDY       0x0002
#define IO_AUX_RX_RDY       0x0003

//aux communcation mode
#define MW_AUX_AUTO           0x00
#define MW_AUX_STX            0x01
#define MW_AUX_ENAC           0x02
#define MW_AUX_SOH_LRC        0x03
#define MW_AUX_SOH_CRC        0x04
#define MW_AUX_NO_PARITY      0x05    // default
#define MW_AUX_EVEN_PARITY    0x06
#define MW_AUX_ODD_PARITY     0x07

// aux speed
#define MW_AUX_9600           0       // default
#define MW_AUX_2400           1
#define MW_AUX_4800           2
#define MW_AUX_19200          3
#define MW_AUX_28800          4
#define MW_AUX_38400          5
#define MW_AUX_57600          6
#define MW_AUX_115200         7
#define MW_AUX_230400         8

struct MW_AUX_CFG {
  BYTE b_len;
  BYTE b_mode;
  BYTE b_speed;
  BYTE b_rx_gap;
  BYTE b_rsp_gap;
  BYTE b_tx_gap;
  BYTE b_retry;
};

// => TCP define
//***********************************
// For IOCtlMW
#define IO_TCP_CONNECT          0x0001
#define IO_TCP_DISCONNECT       0x0002

// tcp mode
#define MW_TCP_PPP_MODE         0x01
#define MW_TCP_NO_CLOSE_WAIT    0x02
#define MW_TCP_SSL_MODE         0x04
#define MW_FTP_SSL_MODE         0x08

// tcp status - MW_TCP_STATUS
#define MW_TCP_STAT_IDLE            0
#define MW_TCP_STAT_CONNECTING      1
#define MW_TCP_STAT_CONNECTED       2
#define MW_TCP_STAT_CLOSING         3
#define MW_TCP_STAT_CLOSED          4
#define MW_TCP_STAT_SSL_CONNECTED   0x8000
#define MW_TCP_STAT_ALERT           0x4000

// tcp status selector
#define MW_TCP_STATUS               0

// tcp status select for tcp tx buffer left
#define MW_TCP_TXBUF_LEFT       1

// tcp status select for tcp rx buffer use
#define MW_TCP_RXBUF_USED       2

// tcp status select to tcb error status
#define MW_TCP_ERR_STATUS       3

// tcp connect parameter define
struct MW_TCP_PORT {
  DWORD d_ip;
  WORD  w_port;
  BYTE  b_sslidx;
  BYTE  b_option;
};

// => UDP define
//***********************************
// For IOCtlMW
#define IO_UDP_CONNECT          0x0001
#define IO_UDP_DISCONNECT       0x0002

// udp mode
#define MW_UDP_SERVER_MODE      0x01
#define MW_UDP_PPP_MODE         0x80

// udp status selector
#define MW_UDP_STATUS               0

// udp status - MW_UDP_STATUS
#define MW_UDP_STAT_IDLE            0
#define MW_UDP_STAT_CONNECTED       1

// udp connect parameter define
struct MW_UDP_PORT {
  DWORD d_ip;
  WORD  w_port;
  BYTE  b_mode;
};

// => ICMP define
//***********************************
struct MW_ICMP_PORT {
  DWORD d_ip;
  BYTE  b_option;
};
// For IOCtlMW
#define IO_ICMP_CONFIG           0x0001
#define IO_ICMP_CONNECT          0x0002
#define IO_ICMP_DISCONNECT       0x0003


// For Option
#define MW_ICMP_PPP_MODE              1

// => FTP define
//***********************************
// For IOCtlMW
#define IO_FTP_CONNECT          0x0001
#define IO_FTP_DISCONNECT       0x0002
#define IO_FTP_CMD_SEND         0x0003
#define IO_FTP_CMD_READ         0x0004

// ftp status - MW_FTP_STATUS
#define MW_FTP_STAT_IDLE            0
#define MW_FTP_STAT_CONNECTING      1
#define MW_FTP_STAT_CONNECTED       2
#define MW_FTP_STAT_OPENING         3
#define MW_FTP_STAT_OPENED          4
#define MW_FTP_STAT_DATA_CONN       5
#define MW_FTP_STAT_DATA_CONNED     6
#define MW_FTP_STAT_CLOSING         7
#define MW_FTP_STAT_SSL_CONNECTED   0x8000
#define MW_FTP_STAT_ALERT           0x4000

// ftp status selector
#define MW_FTP_STATUS               0
#define MW_FTP_CMD_STATUS           1
#define MW_FTP_DATA_STATUS          2
#define MW_FTP_CMD_TXBUF_LEFT       3
#define MW_FTP_DATA_TXBUF_LEFT      4
#define MW_FTP_CMD_RXBUF_USED       5
#define MW_FTP_DATA_RXBUF_USED      6

// ftp disconnect
#define MW_FTP_DATA_CHNL          0
#define MW_FTP_CMD_CHNL           1


// => Modem define
//***********************************
// For IOCtlMW
#define IO_MDM_CONNECT          0x0001
#define IO_MDM_DISCONNECT       0x0002
#define IO_MDM_PHONE_DETECT_ON  0x0003
#define IO_MDM_PHONE_DETECT_OFF 0x0004
#define IO_MDM_PHONE_LINE       0x0005
#define IO_MDM_PHONE_DIAL       0x0006
#define IO_MDM_CID_DETECT       0x0007
#define IO_MDM_CID_READ         0x0008

// For Protocol
#define MW_SDLC                     1
#define MW_ASYNC                    2

// For Mode
#define MW_CCITT                    1
#define MW_BELL                     2

// For Speed
#define MW_300                      0
#define MW_1200                     1
#define MW_2400                     2
#define MW_9600                     3
#define MW_AUTO                     4
#define MW_AUTO_42                  5
#define MW_AUTO_42_CIR              6
#define MW_14400                    7
#define MW_33600                    8
#define MW_56000                    9
#define MW_UNIONPAY_STX            0x80

// For detect mode
#define MW_BUSY_TONE_DETOFF         0x01
#define MW_NO_LINE_CHECK            0x02
#define MW_BLIND_DIALING            0x04
#define MW_SHORT_DIALTONE           0x08

// For Line Status
#define MW_LINE_IDLE               0
#define MW_LINE_DIALING_P1         1
#define MW_LINE_DIALING_P2         2
#define MW_LINE_CONNECTING_P1      3
#define MW_LINE_CONNECTING_P2      4
#define MW_LINE_CONNECTED          5
#define MW_LINE_CD_LOST            0x80
#define MW_LINE_HOST_OFFLINE       0x81
#define MW_LINE_INACT_TIMEOUT      0x82
#define MW_LINE_CONN_FAIL          0x83
#define MW_LINE_CONN_TIMEOUT       0x84
// sticky status, cleared after being read
#define MW_LINE_OCCUPIED           0x00000100
#define MW_LINE_NO_LINE            0x00000200
#define MW_LINE_NO_DAILTONE        0x00000400
#define MW_LINE_WRONG_NO           0x00000800
#define MW_LINE_BUSY               0x00001000
#define MW_LINE_NO_CD              0x00002000
#define MW_LINE_CONNECT_FAIL       0x00004000
#define MW_LINE_MDM_BUSY           0x00008000
#define MW_LINE_MSG_TXED           0x00010000
#define MW_LINE_WAIT_DISC          0x00020000
#define MW_LINE_WAIT_DIAL          0x00040000

struct MW_MDM_PORT {
  BYTE b_protocol;               /* Default SDLC */
  /* 0 - Visa1 */
  /* 1 - SDLC  */
  /* 2 - Async */
  BYTE b_ccitt;                  /* Default CCITT */
  BYTE b_speed;                  /* 0 - 300bps */
  /* 1 - 1200bps */
  /* 2 - 2400bps */
  /* 3 - 9600bps */
  /* 4 - auto */
  /* 5 - auto with V.42 & MNP enable */
  /* 6 - auto with V.42 & MNP enableand using circular */
  /*     buffer supporting Unionpay STX message format in RX */
  /* 7 - 14400bps */
  /* 8 - 33600bps */
  /* 9 - 56000bps */
  /* bit 7 set for support Unionpay STX message format */
  BYTE b_inactivity_tval;        /* in unit of 2.5 sec */
  BYTE b_redial_pause_tval;      /* Pause time between redial in 100 msec*/
  BYTE b_ptel_len;               /* Primary telno length */
  BYTE s_ptel[34];               /* Prime telno */
  BYTE b_pconn_limit;            /* # of connection attempt */
  BYTE b_pconn_tval;             /* Time allowed to wait CD in sec */
  BYTE b_stel_len;               /* Secondary telno length */
  BYTE s_stel[34];               /* Secondary telno */
  BYTE b_sconn_limit;            /* # of connection attempt */
  BYTE b_sconn_tval;             /* Time allowed to wait CD in sec */
  BYTE b_cd_on_qualify_tval;     /* cd on qualify time in 0.25 sec,default 3 */
  BYTE b_cd_off_qualify_tval;    /* cd off qualify time in 0.25 sec,default 4 */
  BYTE b_message_qualify_tval;   /* Message qualify time in 10msec, default 10 */
  BYTE b_wait_online_tval;       /* wait for link online in sec, default 15 */
  BYTE b_tone_duration;          /* tone duration in 10msec */
  BYTE b_holdline_tval;          /* hold line time in second */
  BYTE b_detect_mode;            /* bit 0 - 0 = busy tone detection */
  /*         1 = disable busy tone detection */
  /* bit 1 - 0 = check line before dial */
  /*         1 = no check line */
  /* bit 2 - 0 = blind dialing disable */
  /*         1 = blind dialing enable */
  /* bit 3 - 0 = normal dial tone duration */
  /*         1 = short dial tone duration */
};

// for cid detect mode
#define MW_CID_MODE_NONE             0
#define MW_CID_MODE_USA              1
#define MW_CID_MODE_UK               2
#define MW_CID_MODE_JAPAN            3
#define MW_CID_DEFAULT               1

// for phone detection status
#define MW_PHONE_ONHOOK           0
#define MW_PHONE_OFFHOOK          1
#define MW_PHONE_NOLINE           2
#define MW_PHONE_DETECTNOTENABLE  3


// => PPP define
//***********************************
// For IOCtlMW
enum {
  IO_PPP_SET_DEVICE         ,
  IO_PPP_SET_MTU            ,
  IO_PPP_SET_MODE           ,
  IO_PPP_GET_SPEED          ,
  IO_PPP_SET_SPEED          ,
  IO_PPP_GET_PHASE          ,
  IO_PPP_SET_LOGINID        ,
  IO_PPP_SET_DIAL_SCRIPT    ,
  IO_PPP_SET_ID_STR         ,
  IO_PPP_SET_LOGIN_SCRIPT   ,
  IO_PPP_SET_PHONE          ,
  IO_PPP_SET_DIAL_PARAM     ,
  IO_PPP_SET_REDIAL         ,
  IO_PPP_SET_RECONNECT      ,
  IO_PPP_LOGIN_FINISH       ,
  IO_PPP_SET_TIMEOUT        ,
  IO_PPP_UPTIME             ,
  IO_PPP_SET_ALIVETIME      ,
  IO_PPP_CONNECT            ,
  IO_PPP_DISCONNECT         ,
  IO_PPP_LOGIN_READ         ,
  IO_PPP_LOGIN_WRITE        ,
};

//Expect-Send struct
//It is possible to specify some special `values' in the expect-send script as follows:
//  \c  When used as the last character in a `send' string, this indicates that a newline
//      should not be appended.
//	\d  When the chat script encounters this sequence, it delays two seconds.
//  \p  When the chat script encounters this sequence, it delays for one quarter of a second.
//  \T  This is replaced by the current phone number (see ``set phone'' below).
//  \P  This is replaced by the current authkey value (see ``set authkey'' above).
//  \U  This is replaced by the current authname value (see ``set authname'' above).
//  \j<r1[r2][r3]...>  Reletive jump to other expect_send pair.
//      if jump to the location grater than total expect-send, script done.
//      if jump to location less than 0, script failed.
//
// script contains "expect-send" pair strings for modem communication
//
struct MW_EXPECT_SEND {
  char ** p_expect;     // expect receive strings, the last one must NULL
  WORD  w_min_len;      // min. expect len
  WORD  w_max_len;      // max. expect len
  signed char * p_send; // reply string
  char * p_abort;       // expect receive abort string
  short w_timeout;      // timeout for expect
  BYTE  b_retry;        // no. of retry
  char  b_flags;        // flags
};


#define MW_DEFAULT_SCRIPTS  0xFF    // use default script when no of pair = 0xff

struct MW_PPP_DATA {
  DWORD device;                             // Device id
  DWORD dev_speed;                          // Device Connection Speed
  DWORD id;
  DWORD mtu;                                // Maximun Receive Unit Value
  DWORD mode;                               // PPP mode
  DWORD connect_speed;                      // PPP connection speed
  char  *username;                          // Login User name
  char  *userpwd;                           // Login User password
  struct MW_EXPECT_SEND *dial_scripts;      // Dialup Scirpts
  DWORD  dial_pair;                         // Dialup scripts pairs,  0xFF => Use Default
  char  *id_str;                            // id message
  struct MW_EXPECT_SEND *login_scripts;     // Login Scirpts
  DWORD  login_pair;                        // Login script pairs,    0xFF => Use default
  char  *phone1;                            // Primary phone number
  char  *phone2;                            // Secondary phone number
  struct MW_MDM_PORT line_config;           // Dial parameters
  BYTE  *redial_param;                      // Redial parameters
  DWORD reconnect_waittime;                 // wait time in second before reconnect. (second)
  DWORD reconnect_retry;                    // reconnect retry times
  DWORD login_finish;                       // Send Login finish. 1=> Success 0: User Abort
  DWORD idle_timeout;                       // Idle timeout (second)
  DWORD min_timeout;                        // Minimum Up Time (second)
  DWORD alive_report_time;                  // time to send ping reply (10ms)
};

// PPP device
#define MW_PPP_DEVICE_NONE           0
#define MW_PPP_DEVICE_LINE           1   
#define MW_PPP_DEVICE_AUX1           2
#define MW_PPP_DEVICE_AUX2           3
#define MW_PPP_DEVICE_AUX0           4
#define MW_PPP_DEVICE_GPRS           5
#define MW_PPP_DEVICE_OPENNEG        0x80
#define MW_PPP_DEVICE_FIXIP          0x40             

// PPP mode
#define MW_PPP_MODE_NONE            0x00
#define MW_PPP_MODE_INTERACTIVE     0x01   /* Manual link */
#define MW_PPP_MODE_NORMAL          0x02
#define MW_PPP_MODE_DIRECT          0x04   /* already established */
#define MW_PPP_MODE_DDIAL           0x08   /* Dial immediately, stay connected (dedicate dial) */

// ppp phase
#define MW_PPP_PHASE_IDLE           -1   /* idle not open */
#define	MW_PPP_PHASE_DEAD            0   /* Link is dead */
#define	MW_PPP_PHASE_ESTABLISH       1   /* Establishing link */
#define	MW_PPP_PHASE_AUTHENTICATE    2   /* Being authenticated */
#define	MW_PPP_PHASE_NETWORK         3   /* We're alive ! */
#define	MW_PPP_PHASE_TERMINATE       4   /* Terminating link */
#define MW_PPP_PHASE_READY           5   /* ppp is in a usable state */


// => Codec define
//***********************************
// For IOCtlMW
#define IO_CDC_PLAYFILE       1
#define IO_CDC_PLAYMEM        2
#define IO_CDC_STOP           3

// for Play
struct CODEC_DATA {
  BYTE *content;
  DWORD offset;
  DWORD len;
};

// For Codec Status cmd
#define MW_CODEC_STATUS         0
#define MW_CODEC_VOL            0x80000000

// Codec Status
#define MW_CODEC_OPENED           0x00000001
#define MW_CODEC_PLAYING          0x00000002
#define MW_NOT_WAVEFILE           0x00000100
#define MW_FORMAT_NOTSUPPORT      0x00000200
#define MW_INTERNAL_ERROR         0x00000400
#define MW_FILEOPEN_ERROR         0x00000800
#define MW_FILEREAD_ERROR         0x00001000
#define MW_CODECINIT_ERROR        0x00002000
#define MW_MEMALLOC_ERROR         0x00004000
#define MW_FILESEEK_ERROR         0x00008000
#define MW_READ_ERROR             0x00010000
#define MW_NOTFINISH_ERROR        0x00020000

// USB Serial defines
//***********************************
// For IOCtlMW
//
//
// USBS Status
// bit0-7: Port status, bit8-15: USB state, bit16-23: error code, bit24-31: reserved
#define MW_USB_RXRDY     0x01
#define MW_USB_TXRDY     0x02
// state
#define MW_USB_ATTACHED    	0x0100
#define MW_USB_POWERED   	0x0200
#define MW_USB_DEFAULT   	0x0400
#define MW_USB_ADDRESS   	0x0800
#define MW_USB_CONFIGURED  	0x1000
#define MW_USB_SUSPENDED   	0x2000
// error code
#define MW_USB_LOCKED    0x010000  // end point busy or not available
#define MW_USB_ABORTED   0x020000  // transfer aborted
#define MW_USB_RESET     0x030000  // end point or device reset

// USBSer status selector
#define MW_USBS_STATUS               0


// DNS defines
//***********************************
// For IOCtlMW
#define IO_DNS_REQUEST      1
#define IO_DNS_RESPONSE     2

#define MW_DNS_DEFAULT_PORT      53
#define MW_DNS_MAX_LEN           100

struct DNS_REQ_DATA {
  BYTE  sb_name[MW_DNS_MAX_LEN];
  BYTE  sb_ip[4];
  DWORD d_port;
  DWORD d_timeout;      // timeout value in 10ms, default 10sec
};

// HTTP defines
//***********************************
// For IOCtlMW
#define IO_HTTP_CONNECT      1
#define IO_HTTP_DISCONNECT   2
#define IO_HTTP_REQUEST      3
#define IO_HTTP_RESPONSE     4

// DNS port
#define MW_HTTP_DEFAULT_PORT    80
#define MW_HTTPS_DEFAULT_PORT   443

// Version
#define MW_HTTP_VER1_0     0
#define MW_HTTP_VER1_1     1

#define HTTP_MAX_HOSTBUF       K_HttpMaxHostLen
#define HTTP_MAX_URIBUF        K_HttpMaxUriLen

struct HTTP_INFO {
  BYTE    sb_dns_ip[4];
  WORD    w_dns_port;
  WORD    w_host_port;
  BYTE    s_host[HTTP_MAX_HOSTBUF];
  BYTE    b_sslidx;   // same as tcp
  BYTE    b_option;   // same as tcp
  BYTE    b_version;  // http version
};

// Method
#define MW_HTTP_GET               0
#define MW_HTTP_POST              1

struct HTTP_REQ {
  WORD    w_req_len;
  BYTE    s_uri[HTTP_MAX_URIBUF];
  BYTE    b_method;
  BYTE    b_close;    // set pack close http connection at the end
  BYTE    *p_data;
  WORD    w_max_rlen; // max rx buffer length
  WORD    w_timeout;  // response timeout in unit 10msec, 0 = default 1000 for 10sec
  BYTE    *p_output;
};

// Http status selector
#define MW_HTTP_STATUS              0

// bit0-7 = http status
#define MW_HTTP_IDLE                0
#define MW_HTTP_OPENED              1
#define MW_HTTP_DNSRESOLVE          2
#define MW_HTTP_CONNECTING          3
#define MW_HTTP_CONNECTED           4
#define MW_HTTP_REQUESTED           5

// GPRS defines
//***********************************
// For IOCtlMW
#define IO_GPRS_SETRING             0
#define IO_GPRS_SIGNAL              1
#define IO_GPRS_CMDSEND             2
#define IO_GPRS_CMDRESP             3
#define IO_GPRS_RESET               4
#define IO_GPRS_SMS_DECODE          5
#define IO_GPRS_SMS_ACK             6
#define IO_GPRS_SMS_SEND            7
#define IO_GPRS_SIM_SEL             8
#define IO_GPRS_SLEEP               9

// GPRS status
#define MW_GSTS_ERR                K_GsmError              // gsm initial error
#define MW_GSTS_ON                 K_GsmOn                 // gsm module turned on
#define MW_GSTS_SLEEP              K_GsmSleep              // gsm in sleep mode
#define MW_GSTS_RXREADY            K_GsmRxReady            // data receive ready 
#define MW_GSTS_TXREADY            K_GsmTxReady            // data transmit ready
#define MW_GSTS_ATCMDRDY           K_GsmAtCmdReady         // AT command send ready     
#define MW_GSTS_ATRESPRDY          K_GsmAtRespReady        // at command response ready 
#define MW_GSTS_ATREADY1           K_GsmAtReady1           // initialized, ready to accept AT commands except photobooks, AOC, SMS
#define MW_GSTS_ATREADY2           K_GsmAtReady2           // ready to accept all AT commands
#define MW_GSTS_SIMINSERTED        K_GsmSimInserted        // sim card inserted
#define MW_GSTS_NETWORKAVAIL       K_GsmNetworkAvailable   // gsm network service available                            
#define MW_GSTS_CALLING            K_GsmCalling            // gsm is calling, set after ATD until no carrier           
#define MW_GSTS_GPRSUP             K_GsmGrpsUp             // GPRS is connected, set after <CONNECT> until <NO CARRIER>
#define MW_GSTS_SMSNEWMSG          K_GsmSmsNewMsg          // sms NEW message, will be cleared if read
#define MW_GSTS_RI                 K_GsmRi                 // gsm ring indicator pin, will be cleared if read

struct SMS_ADDR
{
  BYTE b_len;       // len = no. of phone no. digits
  BYTE b_type;
  char sb_addr[20];  // ascii code
};

struct SMS_PDU
{
  struct SMS_ADDR s_smsc;       // sms sevice center address
  BYTE            b_pdu_len;    // pdu length (start from tp_flags)
  BYTE            b_tp_flags;   // sms pdu first octat
  struct SMS_ADDR s_tp_a;       // deliver:originating address, submit:destination address
  BYTE            b_tp_mr;      // message reference
  BYTE            b_tp_st;      // status
  BYTE            b_tp_fcs;     // tp-failure-cause (for RP-ERROR only)
  BYTE            b_tp_pi;      // tp-parameter indicator
  BYTE            b_tp_pid;     // protocol identifier
  BYTE            b_tp_ct;      // command type
  BYTE            b_tp_dcs;     // data coding scheme
  BYTE            sb_tp_time[7]; // deliver:service center time stamp, submit:validity period
  BYTE            sb_tp_dt[7];   // discharge time
  BYTE            b_tp_udl;      // user data len, max. 160 for 7-bit data, othwise max. 140
  BYTE            sb_tp_ud[160]; // user data (ascii code)
};

#define MAX_ATCMD_SIZE  1500

// For GPRS_CMDSEND
struct GPRSATCMD {
  DWORD d_timeout;
  BYTE  sb_content[MAX_ATCMD_SIZE+1];
};

// For GPRS_CMDRESP
struct GPRSATRESP {
  DWORD d_maxlen;
  BYTE  sb_content[MAX_ATCMD_SIZE+1];
};

// SMSs AckType
#define MW_NO_RESP          0       // no reply
#define MW_RESP_ACK         1       // reply ack (with or without pdu)
#define MW_RESP_ERR         2       // reply error (must with pdu)

// SMS destination
#define MW_SMS_DEST         'S'
#define MW_SMS_MEM          'W'

// For GPRS_SMS_xxxx
struct GPRSSMSDATA {
  struct SMS_PDU *s_pdu;
  BYTE           *s_str;
  DWORD          *d_len;
  DWORD          d_ack_type;
  DWORD          d_text_mode;
  DWORD          d_dest;
};

// wmode defines
#define MW_PDUMODE         0
#define MW_TXTMODE         1

// possible values of TP_MTI        Directions
#define MW_SMS_DELIVER      0       // receive
#define MW_SMS_DELREP       0       // send
#define MW_SMS_SUBMIT       1       // send
#define MW_SMS_SUBREP       1       // receive
#define MW_SMS_STSREP       2       // receive
#define MW_SMS_CMD          2       // send

// Thermal Printer defines
//***********************************
// For IOCtlMW
#define IO_TMLPT_CFG                0
#define IO_TMLPT_RESET              2


// For IO_TMLPT_CFG
#define MW_TMLPT_MODE_NORMAL      0
#define MW_TMLPT_MODE_BARCODE     1

struct TMLPTCFG {
  BYTE b_len;               // 5
  BYTE b_mode;              // 0-Normal,  1-barcode
  BYTE b_pwr_speed;         // print speed for power in,    0-4 (22 to 14 lines/sec)
  BYTE b_bat_speed;         // print speed in battary mode  0-4 (16 to 8 lines/sec)
  BYTE b_pwr_strobe;        // strobe width adjustment for power in (+- 0 to 7)
  BYTE b_bat_strobe;        // strobe width adjustment for battery  (+- 0 to 7)
};

// For IO_TMLPT_STATUS
enum {
MW_TMLPT_NORSTATUS         =0,           // Normal Status
MW_TMLPT_ERR_RESTART,                    // Restart on error
MW_TMLPT_ERR_RESET,                      // Reset On error
MW_TMLPT_RESET,                          // Reset
MW_TMLPT_TEMP,                           // Get Temperature
};

// Normal Status
#define MW_TMLPT_SOK                0
#define MW_TMLPT_STEMPHIGH          1
#define MW_TMLPT_SVOLTLOW           2
#define MW_TMLPT_SPAPEROUT          3
#define MW_TMLPT_SERROR             4
#define MW_TMLPT_FTEMPHIGH      0x100
#define MW_TMLPT_FPAPEROUT      0x200
#define MW_TMLPT_FVOLTLOW       0x400
#define MW_TMLPT_FPRINTING      0x800
#define MW_TMLPT_FFINISH       0x1000


//-----------------------------------------------------------------------------
//   Middleware DLL Functions define
//-----------------------------------------------------------------------------
enum {
  STARTUPMW,          // std IO
  SHUTDOWNMW,
  OPENMW,
  CLOSEMW,
  READMW,
  WRITEMW,
  LSEEKMW,
  IOCTLMW,
  STATMW,
  GETLASTERRMW,
  FSYSINITMW,         // file system
  FCREATEMW,
  FDELETEMW,
  FOPENMW,
  FCLOSEMW,
  FLENGTHMW,
  FSEEKMW,
  FREADMW,
  FWRITEMW,
  FCOMMITALLMW,
  FFLUSHMW,
  FDSEARCHMW,
  GETCHARMW,          // keyboard util
  KBDSCODEMW,
  DESKEYMW,           // encrytion util
  DESMW,
  DES2MW,
  DISPLOGOMW,         // LCD display
  ICCINSERTEDMW,      // ICC inserted
  SCHNLSETUPMW,       // Setup Secure Channel with PP300
  SCHNLGETPINMW,      // Get Pin Via Secure Channel
  LLSEEKMW,           //
  DISP_PUTCMW,
  DISP_PUTNMW,
  MW_FUNC_COUNT       // Must be the last item
};

//=> standard I/O api
//extern int Startup(void);
#define StartupMW()           (int) lib_app_call(MIDWARE_ID, STARTUPMW, (DWORD)0, (DWORD)0, (DWORD)0)
//extern int Shutdown(void);
#define ShutdownMW()          (int) lib_app_call(MIDWARE_ID, SHUTDOWNMW, (DWORD)0, (DWORD)0, (DWORD)0)
//extern int Open(char *aDevName, DWORD aFlag);
#define OpenMW(x,y)           (int) lib_app_call(MIDWARE_ID, OPENMW, (DWORD)x, (DWORD)y, 0)
//extern int Close(int aFileDesc);
#define CloseMW(x)            (int) lib_app_call(MIDWARE_ID, CLOSEMW, (DWORD)x, 0, 0)
//extern int Read(int aFileDesc, BYTE *aBuf, int aLen);
#define ReadMW(x,y,z)         (int) lib_app_call(MIDWARE_ID, READMW, (DWORD)x, (DWORD)y, (DWORD)z)
//extern int Write(int aFileDesc, BYTE *aBuf, int aLen);
#define WriteMW(x,y,z)        (int) lib_app_call(MIDWARE_ID, WRITEMW, (DWORD)x, (DWORD)y, (DWORD)z)
//extern int LSeek(int aFileDesc, int aOffSet, int aMode);
#define LSeekMW(x,y,z)        (int) lib_app_call(MIDWARE_ID, LSEEKMW, (DWORD)x, (DWORD)y, (DWORD)z)
//extern int IOCtl(int aFileDesc, int aCmd, void *aParam);
#define IOCtlMW(x,y,z)        (int) lib_app_call(MIDWARE_ID, IOCTLMW, (DWORD)x, (DWORD)y, (DWORD)z)
//extern int Stat(int aFileDesc, int aCmd, void *aParam);
#define StatMW(x,y,z)         (int) lib_app_call(MIDWARE_ID, STATMW, (DWORD)x, (DWORD)y, (DWORD)z)
//extern int GetLastErr(void);
#define GetLastErrMW()        (int) lib_app_call(MIDWARE_ID, GETLASTERRMW, 0, 0, 0)

//=> file system
//extern int fSysInit(void);
#define fSysInitMW()          (int) lib_app_call(MIDWARE_ID, FSYSINITMW, (DWORD)0, (DWORD)0, (DWORD)0)
//extern int fCreate(const char* aFileName, int aAttr);
#define fCreateMW(x,y)        (int) lib_app_call(MIDWARE_ID, FCREATEMW, (DWORD)x, (DWORD)y, (DWORD)0)
//extern int fDelete(const char* aFileName);
#define fDeleteMW(x)          (int) lib_app_call(MIDWARE_ID, FDELETEMW, (DWORD)x, (DWORD)0, (DWORD)0)
//extern int fOpen(const char* aFileName);
#define fOpenMW(x)            (int) lib_app_call(MIDWARE_ID, FOPENMW, (DWORD)x, (DWORD)0, (DWORD)0)
//extern int fClose(int aFileHandle);
#define fCloseMW(x)           (int) lib_app_call(MIDWARE_ID, FCLOSEMW, (DWORD)x, (DWORD)0, (DWORD)0)
//extern int fLength(int aFileHandle);
#define fLengthMW(x)          (int) lib_app_call(MIDWARE_ID, FLENGTHMW, (DWORD)x, (DWORD)0, (DWORD)0)
//extern int fSeek(int aFileHandle, int aOffset);
#define fSeekMW(x,y)          (int) lib_app_call(MIDWARE_ID, FSEEKMW, (DWORD)x, (DWORD)y, (DWORD)0)
//extern int fRead(int aFileHandle, char* aBuf, int aLen);
#define fReadMW(x,y,z)        (int) lib_app_call(MIDWARE_ID, FREADMW, (DWORD)x, (DWORD)y, (DWORD)z)
//extern int fWrite(int aFileHandle, char* aBuf, int aLen);
#define fWriteMW(x,y,z)       (int) lib_app_call(MIDWARE_ID, FWRITEMW, (DWORD)x, (DWORD)y, (DWORD)z)
//extern void fCommitAll(void);
#define fCommitAllMW()        (void) lib_app_call(MIDWARE_ID, FCOMMITALLMW, (DWORD)0, (DWORD)0, (DWORD)0)
//extern int fFlush(int aFileHandle);
#define fFlushMW(x)           (int) lib_app_call(MIDWARE_ID, FFLUSHMW, (DWORD)x, (DWORD)0, (DWORD)0)
//extern int fDSearch(int aReset, struct MW_FILE_HDR* aOutHdr);
#define fDSearchMW(x,y)       (int) lib_app_call(MIDWARE_ID, FDSEARCHMW, (DWORD)x, (DWORD)y, (DWORD)0)

//=> Keyboard functions
//extern DWORD GetChar(void);
#define GetCharMW()           (DWORD) lib_app_call(MIDWARE_ID, GETCHARMW, 0, 0, 0)
//extern DWORD KbdScode(void);
#define KbdScodeMW()          (DWORD) lib_app_call(MIDWARE_ID, KBDSCODEMW, 0, 0, 0)

//=> encrytion functions
//extern void DesKey(void* aKey, DWORD aKeyLen);
#define DesKeyMW(x,y)         (void) lib_app_call(MIDWARE_ID, DESKEYMW, (DWORD)x, (DWORD)y, (DWORD)0)
//extern void Des(void* aData);
#define DesMW(x)              (void) lib_app_call(MIDWARE_ID, DESMW, (DWORD)x, (DWORD)0, (DWORD)0)
//extern void Des2(void* aData);
#define Des2MW(x)            	(void) lib_app_call(MIDWARE_ID, DES2MW, (DWORD)x, (DWORD)0, (DWORD)0)

//=> LCD display functions
//BOOLEAN DispLogo(BYTE const *aPicLogo, BYTE aPosX, BYTE aPosY)
#define DispLogoMW(x,y,z)     (BOOLEAN) lib_app_call(MIDWARE_ID, DISPLOGOMW, (DWORD)x, (DWORD)y, (DWORD)z)

//=> ICC inserted functions
// extern DWORD ICCInserted(void);	// bitwise index output
#define ICCInsertedMW()				(DWORD) lib_app_call(MIDWARE_ID, ICCINSERTEDMW, (DWORD)0, (DWORD)0, (DWORD)0)

//=> MMC/SD inserted functions
// extern BOOLEAN MMCInserted(void);
#define MMCInsertedMW()				(BOOLEAN) sys_func0(OS_FN_MMC_INSERTED)

//=> Lan Cable inserted functions
// extern BOOLEAN LanCableInserted(void);
#define LanCableInsertedMW()        (BOOLEAN) (base_func1(BS_FN_LAN_STATUS, 0)&K_LanPlugIn)

struct MW_KEY {
  DWORD  d_exponent;
  DWORD  d_keysize;
  DWORD  s_key[64];
  DWORD  d_key_idx;
};
//=> CA Key Injection Functions
// BOOLEAN InjectCAKey(struct MW_KEY * a_key);
#define InjectCAKeyMW(x)        base_func1(BS_FN_CAKEY_INJECT,(DWORD)(x))

//=> Secur Channel (Aux Port) use with PP300
//BOOLEAN SChnlSetup(char *aDevStr, BOOLEAN aInjectNewKey);
#define SChnlSetupMW(x, y)    (BOOLEAN) lib_app_call(MIDWARE_ID, SCHNLSETUPMW, (DWORD)x, (DWORD)y, 0)

// GetPin Mode Support
#define MW_PIN_DEF    0x00
#define MW_PIN_CUP    0x10
#define MW_PIN_BJ     0x20
#define MW_PIN_SZEPS  0x30
#define MW_PIN_HKEPS1 0x40
#define MW_PIN_HKEPS2 0x50
#define MW_PIN_BOC    0x60

// aIOBlk Data = timeout(1) + mode(1) + dummy(13) + BCD Amount(6) + Prompt Msg(?)
// Refer to PP300 manaual for details (KBD Input PIN section)
//DWORD SChnlGetPin(BYTE *aIOBlk, BYTE aBlkLen);
#define SChnlGetPinMW(x, y)   (DWORD) lib_app_call(MIDWARE_ID, SCHNLGETPINMW, (DWORD)x, (DWORD)y, 0)

//extern int LLSeek(int aFileDesc, DDWORD *aOffSet, int aMode);
#define LLSeekMW(x,y,z)        (int) lib_app_call(MIDWARE_ID, LLSEEKMW, (DWORD)x, (DWORD)y, (DWORD)z)

#ifdef SUPPORT_128X64
//***********************************
// 128x64 LCD display
//***********************************
#define MWCUR_RIGHT             0x01
#define MWCUR_LEFT              0x02
#define MWCUR_DOWN              0x03
#define MWCUR_UP                0x04
#define MWDEL_EOL               0x05
#define MWBELL                  0x07
#define MWBACK_SP               0x08
#define MWNEW_LINE              0x0A
#define MWCUR_HOME              0x0B
#define MWCLR_HOME              0x0C
#define MWC_RETURN              0x0D
#define MWPUSH_CURSOR           0x0E
#define MWPOP_CURSOR            0x0F
#define MWSEL_SMFONT            0x10
#define MWSEL_BIGFONT           0x11
#define MWSEL_SPFONT            0x12
#define MWSEL_BIGUSERFONT       0x13
#define MWSEL_SMUSERFONT        0x14
#define MWSEL_SPUSERFONT        0x15
#define MWSEL_BIGUSERFONT_T     0x16
#define MWESC                   0x1B
#define MWREV_ON                0x1C
#define MWREV_OFF               0x1D

#define MWLINE1        0x00
#define MWLINE2        0x20
#define MWLINE3        0x40
#define MWLINE4        0x60
#define MWLINE5        0x80
#define MWLINE6        0xA0
#define MWLINE7        0xC0
#define MWLINE8        0xE0

//void PrintfMW(const char *aFormatStr[,aArgument....])
extern int printfmw(const unsigned char *format, ...);
#define PrintfMW            printfmw
#define PutCharMW(x)                lib_app_call(MIDWARE_ID, DISP_PUTCMW, (DWORD)(x), 0, 0)
#define PutNCharMW(x,y)    {BYTE *ptr = os_malloc(y);\
                            if (ptr != NULL) {\
                              memcpy(ptr, (BYTE *)x, y);\
                              lib_app_call(MIDWARE_ID, DISP_PUTNMW, (DWORD)ptr, (DWORD)y, 0);\
                              os_free(ptr);}}
                        


#define DispFlushMW()               sys_func1(OS_FN_DISP_PUTC,(DWORD)(MWCLR_HOME))
#define DispContSetMW(x)            
/*
icon image bit pattern
bit 0 - signal 0
bit 1 - signal 1
bit 2 - signal 2
bit 3 - signal 3
bit 4 - signal 4
bit 5 - antenna
bit 6 - left triangle outside
bit 7 - left triangle inside and right triangle outside
bit 8 - right triangle inside
bit 9 - left square outside
bit 10- left square inside and right square outside
bit 11- right square inside
bit 12- left circle outside
bit 13- left circle inside and right circle outside
bit 14- right circle inside
bit 15- left star outside
bit 16- left star inside and right star outside
bit 17- right star inside
bit 18- left down triangle outside
bit 19- left down triangle inside and right down triangle outside
bit 20- right down triangle inside
bit 21- left cross star outside
bit 22- left cross star inside and right cross star outside
bit 23- right cross star inside
bit 24- battery frame
bit 25- battery level 1
bit 26- battery level 2
bit 27- battery level 3
bit 28- battery level 4
*/
// DWORD os_disp_icon_set(DWORD a_image);
#define DispIconSetMW(x)            sys_func1(OS_FN_DISP_ICON_SET,(DWORD)(x))
// DWORD os_disp_icon_clear(DWORD a_image);
#define DispIconClearMW(x)          sys_func1(OS_FN_DISP_ICON_CLEAR,(DWORD)(x))
// void os_backlight_control(DWORD a_state);
#define DispBlOnOffMW(x)            sys_func1(OS_FN_BACKLIGHT_CONTROL,(DWORD)(x))
// void os_backlight_time(DWORD a_time);
#define DispBlTimerSetMW(x)         sys_func1(OS_FN_BACKLIGHT_TIME,(DWORD)(x))
#endif // SUPPORT_128X64

#ifdef SUPPORT_320X240
//***********************************
// => 320x240 LCD display
//***********************************
// command define
#define MW_LCUR_RIGHT             0x01
#define MW_LCUR_LEFT              0x02
#define MW_LCUR_DOWN              0x03
#define MW_LCUR_UP                0x04
#define MW_LDEL_EOL               0x05
#define MW_LBELL                  0x07
#define MW_LBACK_SP               0x08
#define MW_LNEW_LINE              0x0A
#define MW_LCUR_HOME              0x0B
#define MW_LCLR_HOME              0x0C
#define MW_LC_RETURN              0x0D
#define MW_LPUSH_CURSOR           0x0E
#define MW_LPOP_CURSOR            0x0F
#define MW_LSEL_SMFONT            0x10
#define MW_LSEL_BIGFONT           0x11
#define MW_LSEL_SPFONT            0x12
#define MW_LSEL_BIGUSERFONT       0x13
#define MW_LSEL_SMUSERFONT        0x14
#define MW_LSEL_SPUSERFONT        0x15
#define MW_LSEL_BIGUSERFONT_T     0x16
#define MW_LSET_TXTCOLOR          0x17
#define MW_LSET_BKCOLOR           0x18
#define MW_LESC                   0x1B
#define MW_LREV_ON                0x1C
#define MW_LREV_OFF               0x1D

// Line define
#define MW_LLINE1                 0x01
#define MW_LLINE2                 0x02
#define MW_LLINE3                 0x03
#define MW_LLINE4                 0x04
#define MW_LLINE5                 0x05
#define MW_LLINE6                 0x06
#define MW_LLINE7                 0x07
#define MW_LLINE8                 0x08
#define MW_LLINE9                 0x09

// column define
#define MW_LCOL1                  0x01
#define MW_LCOL2                  0x02
#define MW_LCOL3                  0x03
#define MW_LCOL4                  0x04
#define MW_LCOL5                  0x05
#define MW_LCOL6                  0x06
#define MW_LCOL7                  0x07
#define MW_LCOL8                  0x08
#define MW_LCOL9                  0x09
#define MW_LCOL10                 0x0A
#define MW_LCOL11                 0x0B
#define MW_LCOL12                 0x0C
#define MW_LCOL13                 0x0D
#define MW_LCOL14                 0x0E
#define MW_LCOL15                 0x0F
#define MW_LCOL16                 0x10
#define MW_LCOL17                 0x11
#define MW_LCOL18                 0x12
#define MW_LCOL19                 0x13
#define MW_LCOL20                 0x14
#define MW_LCOL21                 0x15
#define MW_LCOL22                 0x16
#define MW_LCOL23                 0x17
#define MW_LCOL24                 0x18
#define MW_LCOL25                 0x19
#define MW_LCOL26                 0x1A

//void PrintfMW(const char *aFormatStr[,aArgument....])
//extern int printf(const unsigned char *format, ...);
#define CPrintfMW            printf

// BYTE CPutCharMW(DWORD a_c);
#define CPutCharMW(x)             sys_func1(OS_FN_DISP_PUTC,(DWORD)(x))

// void CPutCharMW(void * a_str,DWORD a_count);
#define CPutNCharMW(x,y)          sys_func2(OS_FN_DISP_PUTN,(DWORD)(x),(DWORD)(y))
#define CDispFlushMW()            sys_func1(OS_FN_DISP_PUTC,(DWORD)(K_ClrHome))
#define CDispSetPos(x,y)          sys_func1(OS_FN_DISP_PUTP,(DWORD)(((x<<8)|(y&0xFF))&0xFFFF))

struct CGRAPH {
  WORD  w_hstart; // start pixel horizontal start position
  WORD  w_vstart; // start pixel vertical start position
  WORD  w_hwidth; // horizontal pixel width, x
  WORD  w_vwidth; // vertical pixel width, y
  BYTE  sb_data[1];  // pointer to graphical data to be saved or displayed, len = x * y WORD
};

// void DispGetG(struct CGRAPH *aDat);
#define DispGetGMW(x)                 sys_func1(OS_FN_DISP_GETG,(DWORD)(x))

// void DispPutG(struct CGRAPH *aDat);
#define DispPutGMW(x)                 sys_func1(OS_FN_DISP_PUTG,(DWORD)(x))

// DWORD os_disp_brightness(DWORD a_brightness); // 0-7, 7 = brightest
#define DispBrightMW(x)               sys_func1(OS_FN_DISP_BRIGHTNESS, (DWORD)x)

// DWORD os_disp_bl_control(DWORD a_time); // 0 = off now, 0xff = on now
#define DispBLCtrlMW(x)               sys_func1(OS_FN_DISP_BL_CONTROL, (DWORD)x)

#endif // SUPPORT_320X240

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//  Display Functions
//-----------------------------------------------------------------------------
#ifdef SUPPORT_128X64
  #define MW_NOR_LINESIZE          (16)
  #define MW_MAX_LINESIZE          (21)
  // Line number defines
  #define MW_LINE1                 0x0000
  #define MW_LINE2                 0x0200
  #define MW_LINE3                 0x0400
  #define MW_LINE4                 0x0600
  #define MW_LINE5                 0x0800
  #define MW_LINE6                 0x0A00
  #define MW_LINE7                 0x0C00
  #define MW_LINE8                 0x0E00
  #define MW_LINE9                 0x0000
  #define MW_MAX_LINE              MW_LINE8
#elif defined SUPPORT_320X240
  #define MW_NOR_LINESIZE          (20)
  #define MW_MAX_LINESIZE          (26)
  // Line number defines
  #define MW_LINE1                 0x0100
  #define MW_LINE2                 0x0200
  #define MW_LINE3                 0x0300
  #define MW_LINE4                 0x0400
  #define MW_LINE5                 0x0500
  #define MW_LINE6                 0x0600
  #define MW_LINE7                 0x0700
  #define MW_LINE8                 0x0800
  #define MW_LINE9                 0x0900
  #define MW_MAX_LINE              MW_LINE9
#else
  NEW_LCD_TYPTE_HERE
#endif

//-----------------------------------
// SU_SMFONT  => LCD=8xNormal Line Size
// SU_BIGFONT => LCD=4xNormal Line Size
// SU_SPFONT  => LCD=8xMax Line Size
#define MW_SMFONT               0x0000
#define MW_BIGFONT              0x1000
#define MW_SPFONT               0x2000
#define MW_SPCHI                0x3000
#define MW_8X16FONT             0x4000
#define MW_8X8FONT              0x5000
#define MW_6X8FONT              0x6000
#define MW_8X16TFONT            0x7000
#define MAX_MW_FONT             0x08

// Control
#define MW_LEFT                  0x00
#define MW_RIGHT                 0x01
#define MW_CENTER                0x02

// Option
#define MW_REVERSE               0x10
#define MW_CLREOL                0x20
#define MW_CLRDISP               0x80

#define FONT_IDX(x)            (x>>12)

// Display Control Character
#define MW_CLR_DISP          K_ClrHome
#define MW_REV_ON            K_RevOn
#define MW_REV_OFF           K_RevOff
#define DispCtrlMW(x)        os_disp_putc(x)
#define ClearDispMW()        os_disp_putc(K_ClrHome)
#define DispPutCMW(x)        os_disp_putc(x)
#define DispPutNCMW(x, y)    os_disp_putn(x,y)

#if (T800|R700|TIRO|PR608) //for old terminal mw not support such features
  extern DWORD mwClearLine(DWORD aLineNo, DWORD aReverse);
  extern DWORD mwClrBelow(DWORD aLineNo);
  extern DWORD mwDispGotoXY(DWORD aOffset, DWORD aFont);
  extern DWORD mwDispLine(const void *aMsg, DWORD aOffset, DWORD aCtrl);
  #define DispClrLineMW(x)              mwClearLine(x,0)
  #define DispClrBelowMW(x)             mwClrBelow(x)
  #define DispGotoMW(x, y)              mwDispGotoXY(x,y)
  #define DispLineMW(x, y, z)           mwDispLine(x,y,z)
#else
  //extern void ClearLineMW(DWORD aLineNo);
  //extern void ClrBelowMW(DWORD aLineNo);
  // aOffset = SU_LINEx + offset
  // aCtrl   = SU_xxFont + Option + Control
  //extern void DispGotoMW(DWORD aOffset, DWORD aFont);
  //extern void DispLineMW(const BYTE *aMsg, DWORD aOffset, DWORD aCtrl);
  #define DispClrLineMW(x)              lib_app_call(MIDWARE_ID, DISP_CLRLINEMW, (DWORD)(x), 0, 0)
  #define DispClrBelowMW(x)             lib_app_call(MIDWARE_ID, DISP_CLRBELOWMW, (DWORD)(x), 0, 0)
  #define DispGotoMW(x, y)              lib_app_call(MIDWARE_ID, DISP_GOTOMW, (DWORD)x, (DWORD)y, 0)
  #define DispLineMW(x, y, z)           {                                     \
    DWORD len = strlen((const char *)x);                                      \
    BYTE *ptr = os_malloc(len+1);                                             \
    if (ptr != NULL) {                                                        \
      memcpy(ptr, x, len);                                                    \
      ptr[len] = 0;                                                           \
      lib_app_call(MIDWARE_ID, DISP_LINEMW, (DWORD)ptr, (DWORD)y, (DWORD)z);  \
      os_free(ptr);                                                           \
    }                                                                         \
  }
#endif
//-----------------------------------------------------------------------------
#endif //_INC_MIDWARE_H_



